package com.zhuss.repair.processor;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import com.zhuss.bean.bo.repair.repair.BackRepairBo;
import com.zhuss.bean.bo.repair.repair.DeleteRepairBo;
import com.zhuss.bean.bo.repair.repairAudit.RepairAuditPaiDanBo;
import com.zhuss.bean.vo.repair.repair.DetailRepairVo;
import com.zhuss.common.AbstractProcessor;
import com.zhuss.common.Processor;
import com.zhuss.db.entity.OpLog;
import com.zhuss.enums.LogActionEnum;
import com.zhuss.enums.MoudleEnum;
import com.zhuss.enums.RepairEnum;
import com.zhuss.exception.WpsException;
import com.zhuss.repair.db.dao.ext.RepairAuditDao;
import com.zhuss.repair.db.dao.ext.RepairDao;
import com.zhuss.repair.db.entity.Repair;
import com.zhuss.repair.db.entity.RepairAudit;
import com.zhuss.util.JsonUtil;

/**
 * 删除餐品 processor
 * @Author: zhushanshuo
 * @Date: 2020/02/28 16:01
 */
@Component("repairAuditPaiDan")
public class RepairAuditPaiDan extends AbstractProcessor<Object, RepairAuditPaiDanBo> implements Processor<Object, RepairAuditPaiDanBo> {

    @Autowired
    private RepairAuditDao repairAuditDao;
    
    
    /**
     * 校验
     */
	@Override
	@SuppressWarnings("unchecked")
    public void check(RepairAuditPaiDanBo bo) throws WpsException {
    	/*Long repairId = bo.getRepairId();
    	List<Long> permissionIdList = (List<Long>) repairPermissionRead.listPermissionId(repairId);
    	if (!permissionIdList.isEmpty()) {
    		throw new WpsException(ExceptionCode.不能删除已绑定权限的餐品);
    	}
    	List<Long> userIdList = (List<Long>) userRepairRead.listUserId(repairId);
    	if (!userIdList.isEmpty()) {
    		throw new WpsException(ExceptionCode.不能删除已绑定用户的餐品);
    	}*/
    }
    
    /**
     * 操作方法
     */
    @Override
    public Object process(RepairAuditPaiDanBo param) throws WpsException {
    	Integer repairId = param.getId();
    	/*String name = ((DetailRepairVo) repairRead.detail(11)).getName();*/
    	RepairAudit repairAudit = new RepairAudit();
    	repairAudit.setRepair_id(param.getRepair_id());
    	repairAudit.setWuye_id(param.getWuye_id());
    	repairAudit.setReply_time(param.getReply_time());
    	repairAudit.setDeal_user_id(param.getDeal_user_id());//param.getConcurrentUserId()
    	repairAudit.setRemark(param.getRemark());
    	repairAudit.setAudit(RepairEnum.报修派单.getAudit());	//2
    	repairAudit.setWeixiu_user_id(param.getWeixiu_user_id());
    	repairAuditDao.deleteAudit(repairAudit);
    	repairAuditDao.insertPaiDan(repairAudit);
    	RepairAudit record = new RepairAudit();
    	record.setStep(RepairEnum.报修派单.getStep());
    	record.setAudit(RepairEnum.报修派单.getAudit());
    	record.setRepair_id(param.getRepair_id());
    	repairAuditDao.updateRepairStatus(record);
        return null;
    }
    
    /**
     * 操作日志
     */
	@Override
	public Object log(RepairAuditPaiDanBo param) throws WpsException {
		OpLog record = new OpLog();
    	record.setMoudle(MoudleEnum.报修审核.key());
    	record.setAction(LogActionEnum.报修派单.key());
    	/*record.setTargetId(param.getRepairId().longValue());*/
    	/*record.setTargetName(param.getName());*/
    	record.setContent("参数: " + JsonUtil.toJson(param));
    	record.setReason(param.getExceptionReason());
    	record.setCreatorId(param.getConcurrentUserId());
    	record.setCreator(param.getConcurrentUserName());
    	record.setCreateTime(new Date());
    	log(record);
    	return null;
	}
}
